<?php

namespace Home\Model\Ajax;

class UserFindpwdSave extends AbstractAjax
{
    public function handle()
    {
        $SMSopen     = C('YTATA_SMS_OPEN');
        $mobile      = I('request.mobile');
        $password    = I('request.password', '', 'trim');
        $code        = I('request.code', '', 'trim');
        $mobile_code = session('mobile_code');
        $mobile_post = session('mobile_post');
        if (empty($SMSopen)) {
            $ajax['status']  = 0;
            $ajax['content'] = '手机短信功未打开，无法找密码！';
            return $ajax;
        }
        if (empty($code) || $code <> $mobile_code) {
            $ajax['status']  = 0;
            $ajax['content'] = '验证码错误，请重新输入';
            return $ajax;
        }
        if (empty($mobile) || $mobile <> $mobile_post) {
            $ajax['status']  = 0;
            $ajax['content'] = '手机号填写错误';
            return $ajax;
        }
        if (empty($password)) {
            $ajax['status']  = 0;
            $ajax['content'] = '必须填写新密码！';
            return $ajax;
        }
        $user = D('User')->get_user_one($mobile, false, 2);
        D('User')->edit_pwd($user['uid'], $password);
        $ajax['status']  = 1;
        $ajax['content'] = '新密码设置成功，请重新登录！';
        return $ajax;
    }
}